<template>
    <div>
        <Row :gutter="10">
            <Col span="24">
            <Card class="slideList">
                <p slot="title" style="height: 26px">
                    <Icon type="ios-albums-outline"></Icon>
                    充值订单
                    <a href="http://192.168.1.143:8976/api/v1/admin/pay/excel">导出Excel表格</a>
                </p>
                <div class="edittable-table-height-con">
                    <Table :columns="slideTableHead" :data="accuseList" border :no-filtered-data-text="tipeNews" :no-data-text="tipeNews" ref="slideTableHead"></Table>
                </div>
            </Card>
            </Col>
        </Row>
        <Page :total="total" :current="page" :page-size="pageSize" @on-change="onCurrentChange" style="text-align: center"></Page>
    </div>
</template>
<script>
    export default {
        data () {
            return {
                //表头
                slideTableHead:[
                    {
                        title: '会员昵称',
                        align: 'center',
                        key: 'nickName',
                    },
                    {
                        title: '会员编号',
                        align: 'center',
                        key: 'mIdNo',
                    },
                    {
                        title: '第三方支付',
                        align: 'center',
                        key: 'transaction_id',
                    },
                    {
                        title:'结算状态',
                        key:'settlement_code',
                        align:'center',
                        width:'100',
                        filters: [
                            {label: '未结算', value: 0},
                            {label: '已结算',value: 1},
                        ],
                        filterMultiple:false,
                        filterMethod (v,r){
                            if (v === 0) {
                                return r.settlement_code === 0;
                            } else if (v === 1) {
                                return r.settlement_code === 1;
                            }
                        },
                        render(h,params,index){
                            const row = params.row;
                            if(row.settlement_code=="0"){
                                return h('div', [
                                    h('div', {
                                        style: {
                                            color:'#990000'
                                        },
                                    }, '未结算'),
                                ]);
                            }else if (row.settlement_code=="1"){
                                return h('div', [
                                    h('div', {
                                        style: {
                                            color:'#19be6b'
                                        },
                                    }, '已结算'),
                                ]);
                            }
                        },
                    },
                    {
                        title:'支付方式',
                        key:'channel',
                        width:'100',
                        align:'center',
                        filters: [
                            {label: '爱吧收银台',value: 0},
                            {label: '支付宝',value: 1},
                            {label: '微信',value: 2},
                        ],
                        filterMultiple:false,
                        filterMethod (v,r){
                            if (v === 0) {
                                return r.channel === 0;
                            } else if (v === 1) {
                                return r.channel === 1;
                            }else if (v === 2) {
                                return r.channel === 2;
                            }
                        },
                        render(h,params,index){
                            const row = params.row;
                            if(row.channel==0){
                                return "爱吧收银台";
                            }else if(row.channel==1){
                                return "支付宝";
                            }else if(row.channel==2){
                                return "微信";
                            }
                        },
                    },

                    {
                        title: '错误代码',
                        align: 'center',
                        key: 'err_code',
                    },
                    {
                        title: '错误描述',
                        align: 'center',
                        key: 'err_code_des',
                    },
                    {
                        title: '无折金币',
                        align: 'center',
                        key: 'old_gold',
                    },
                    {
                        title: '结算日期',
                        align: 'center',
                        key: 'settlement_time',
                    },

                    {
                        title: '货币单位',
                        align: 'center',
                        key: 'price_unit',
                    },
                    {
                        title: '对应金币',
                        align: 'center',
                        key: 'gold',
                    },
                    {
                        title: '订单号',
                        align: 'center',
                        key: 'out_trade_no',
                    },
                    {
                        title: '订单金额',
                        align: 'center',
                        key: 'price',
                    },

                    {
                        title: '业务结果',
                        align: 'center',
                        key: 'result_code',
                    },
                    {
                        title: '开始时间',
                        align: 'center',
                        key: 'time',
                    },
                    {
                        title: '完成时间',
                        align: 'center',
                        key: 'time_end',
                    },
                    {
                        title:'订单状态',
                        key:'status',
                        align:'center',
                        width:'100',
                        filters: [
                            {label: '已取消',value: -1},
                            {label: '待支付', value: 0},
                            {label: '已完成',value: 1},
                        ],
                        filterMultiple:false,
                        filterMethod (v,r){
                            if (v === -1) {
                                return r.status === -1;
                            } else if (v === 0) {
                                return r.status === 0;
                            }else if (v === 1) {
                                return r.status === 1;
                            }
                        },
                        render(h,params,index){
                            const row = params.row;
                            if(row.status==-1){
                                return h('div', [
                                    h('div', {
                                        style: {
                                            color:'#990000'
                                        },
                                    }, '已取消'),
                                ]);
                            }else if (row.status==0){
                                return h('div', [
                                    h('div', {
                                        style: {
                                            color:'#ff9900'
                                        },
                                    }, '待支付'),
                                ]);
                            }else if (row.status==1){
                                return h('div', [
                                    h('div', {
                                        style: {
                                            color:'#19be6b'
                                        },
                                    }, '已完成'),
                                ]);
                            }
                        },
                    },
                ],
                selectURl:'/pay/list',
                excelURl:'/pay/excel',
                accuseList:[],
                tipeNews:'暂无数据',
                total:0,
                pageSize:0,
                page:1,

            }
        },
        created () {
            this.getData();
        },
        methods: {
            //初始化时获取数据
            getData () {
                let self = this;
                self.$axios.get(self.selectURl + '?curr=' + self.page).then((res) => {
                    for (var i = 0; i < res.data.data.rows.length; i++) {
                        let time = new Date(res.data.data.rows[i].time).toLocaleString();
                        let time_end = new Date(res.data.data.rows[i].time_end).toLocaleString();
                        let settlement_time = new Date(res.data.data.rows[i].settlement_time).toLocaleString();
                        res.data.data.rows[i].time = time;
                        res.data.data.rows[i].time_end = time_end;
                        res.data.data.rows[i].settlement_time = settlement_time;
                    }
                    self.accuseList = res.data.data.rows;
                    self.page = res.data.data.page;
                    self.pageSize = res.data.data.pagesize;
                    self.total = res.data.data.total;
                })
            },
            onCurrentChange(val){
                let self = this;
                self.page = val;
                self.getData();
            }

        }
    }
</script>